//
//  CustomSuccessAlertView.m
//  DriverClient
//
//  Created by 吕晶 on 2020/8/4.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CustomSuccessAlertView.h"

@interface CustomSuccessAlertView ()

@property (nonatomic, strong) UILabel *titleLab;

@end

@implementation CustomSuccessAlertView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, ScreenW, ScreenH);
        self.backgroundColor = HexColorA(0x000000, 0.5);
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(30, (ScreenH - 237) * 0.5, ScreenW - 60, 237)];
        bgView.backgroundColor = HexColor(0xffffff);
        bgView.layer.cornerRadius = 6;
        [self addSubview:bgView];
        
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake((bgView.nim_width - 72) * 0.5, 47, 72, 72)];
        imgView.image = [UIImage imageNamed:@"success_alert"];
        [bgView addSubview:imgView];
        
        self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, imgView.nim_bottom + 15, bgView.nim_width, 17)];
        self.titleLab.font = BoldFontOfSize(16);
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.textAlignment = NSTextAlignmentCenter;
        [bgView addSubview:self.titleLab];
        
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake((bgView.nim_width - 60) * 0.5, bgView.nim_height - 40, 60, 40)];
        [btn setTitle:@"确认" forState:0];
        [btn setTitleColor:Color_ThemeColor forState:0];
        btn.titleLabel.font = BoldFontOfSize(16);
        [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:btn];
    }
    return self;
}

- (void)btnClick {
    [self disMissView];
    if (self.finishBlock) {
        self.finishBlock();
    }
}

-(void)setText:(NSString *)text {
    _text = text;
    self.titleLab.text = text;
}

- (void)showInView:(UIView *)view {
    if (!view) {
        return;
    }
    [view addSubview:self];
}

- (void)disMissView {
    [self removeFromSuperview];
}

@end
